package com.chencs.app.lianmeng.service;
import com.chencs.app.AppCommon;
import com.chencs.app.lianmeng.mapper.LMBannerMapper;
import com.chencs.vo.biz.lianmeng.LmBanner;
import com.chencs.vo.net.lmrequest.LmBannerRequest;
import com.chencs.vo.net.lmresponse.LmBannerResponse;
import com.chencs.vo.net.request.RequestBase;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class LMBannerSer {



    @Autowired
    private LMBannerMapper mapper;

    /**
     * 获取首页轮播图
     * @param request
     * @return
     */
    public LmBannerResponse getSlideBanner(RequestBase request){
        LmBannerResponse response = new LmBannerResponse();
         List<LmBanner> list = mapper.getSlideBanner();
            if(CollectionUtils.isEmpty(list)){
                response.setCode(AppCommon.NULL);
                response.setMsg("暂无数据");
            }else{
                response.setBanners(list);
                response.setCode(AppCommon.SUCCESS);
                response.setMsg("获取成功");
            }
        return  response;
    }


    /**
     * 获取启动图轮播图
     * @param request
     * @return
     */
    public LmBannerResponse getStartBanner(RequestBase request){
        LmBannerResponse response = new LmBannerResponse();
        List<LmBanner> list = mapper.getStartBanner();
        if(CollectionUtils.isEmpty(list)){
            response.setCode(AppCommon.NULL);
            response.setMsg("暂无数据");
        }else{
            response.setBanners(list);
            response.setCode(AppCommon.SUCCESS);
            response.setMsg("获取成功");
        }
        return  response;
    }


    /**
     * 获取首页弹窗
     * @param request
     * @return
     */
    public LmBannerResponse getPopBanner(RequestBase request){
        LmBannerResponse response = new LmBannerResponse();
        List<LmBanner> list = mapper.getPopBanner();
        if(CollectionUtils.isEmpty(list)){
            response.setCode(AppCommon.NULL);
            response.setMsg("暂无数据");
        }else{
            response.setBanners(list);
            response.setCode(AppCommon.SUCCESS);
            response.setMsg("获取成功");
        }
        return  response;
    }

    /**
     * 更具关键词取出广告图
     * @param request
     * @return
     */
    public LmBannerResponse getBannerByKey(LmBannerRequest request){
        LmBannerResponse response = new LmBannerResponse();
        LmBanner lmBanner = mapper.getBannerByKey(request.getKey());

        if(lmBanner==null){
            response.setCode(AppCommon.NULL);
            response.setMsg("暂无数据");
        }else{
            response.setBanner(lmBanner);
            response.setCode(AppCommon.SUCCESS);
            response.setMsg("获取成功");
        }
        return  response;

    }



}
